package com.brush.brushbasicapi.controller;

import com.brush.brushcommon.common.BaseController;
import com.brush.brushcommon.common.basic.pojo.Category;
import com.brush.brushcommon.common.basic.service.CategoryService;
import com.brush.brushcommon.common.sys.pojo.User;
import com.brush.brushcommon.dto.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 题库分类表 前端控制器
 * </p>
 *
 * @author debug
 * @since 2024-07-14
 */
@RestController
@RequestMapping("/category")
@Tag(name = "题库分类")
public class CategoryController extends BaseController {

    @Autowired
    private CategoryService categoryService;


    @Operation(summary = "分类tree")
    @PostMapping("/list")
    @Parameters({
            @Parameter(name = "Authorization", description = "请求token", required = true, in = ParameterIn.HEADER)
    })
    public Result treeList(@RequestParam(value = "categoryName", required = false,name = "categoryName")String categoryName) {
        return categoryService.treeList(categoryName);
    }


    @Operation(summary = "添加分类")
    @PostMapping("/addCategory")
    @Parameters({
            @Parameter(name = "Authorization", description = "请求token", required = true, in = ParameterIn.HEADER)
    })
    public Result addCategory(@RequestBody Category category) {
        User userInfo = getUserInfo();
        category.setGmtFounder(userInfo.getId());
        return categoryService.addCategory(category);
    }


    @Operation(summary = "修改分类")
    @PutMapping("/updateCategory")
    @Parameters({
            @Parameter(name = "Authorization", description = "请求token", required = true, in = ParameterIn.HEADER),
    })
    public Result updateCategory(@RequestBody Category category) {
        User userInfo = getUserInfo();
        category.setGmtFounder(userInfo.getId());
        return categoryService.updateCategory(category);
    }

    @Operation(summary = "（单）删除分类",description = "删除单个时如有子集无法删除，删除时及删除绑定的系统题库")
    @DeleteMapping("/deleteCategory")
    @Parameters({
            @Parameter(name = "Authorization", description = "请求token", required = true, in = ParameterIn.HEADER),
    })
    public Result deleteCategory(@RequestParam(value = "id", required = true,name = "id")String id) {
        return categoryService.deleteCategory(id);
    }



    @Operation(summary = "（批量）删除分类",description = "复选框选择删除:ids复选框选择的全部id数据")
    @DeleteMapping("/deleteCategoryBatch")
    @Parameters({
            @Parameter(name = "Authorization", description = "请求token", required = true, in = ParameterIn.HEADER),
    })
    public Result deleteCategoryBatch(@RequestParam(value = "ids", required = true,name = "ids") List<String> ids) {
        return categoryService.deleteCategoryBatch(ids);
    }



}
